home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
disk
/
mt100.zip
/
MTMEM.ASM
< prev
next >
Wrap
Assembly Source File
|
1996-06-04
|
11KB
|
285 lines
; MTMem - Memory to store mtdirs and mtprev[] for Move To (mt.com)
; Copyright Jason Hood 1996.
; Started: 5 May, 1996.
; Finished: 2 June.
;
; Usage: in the autoexec.bat file place these statements:
; set mtmem=####
; mtmem [d:/path] [;path] [;;path]
; Where: [d:/path] is the path to place the directory structure file.
; Default is the same path as mtmem.com.
; [;path] is the initial previous directory.
; Default is an empty string ("Directory does not exist.").
; [;;path] is the initial before previous directory.
; Default as above.
; The environment variable will be set to the segment address of the
; allocated memory.
;
; Assumptions: all parameters are valid
; environment variable MTMEM is set correctly, or not set at all
; DOS 3.0+ (5.0+ for high memory)
; Memory is available
;
; Acknowledgements: Ralf Brown's interrupt list for PSP/environment information
; and his AMIS.ASM for allocating memory.
; Howard Vigorita's ATIM.ASM for the paragraph length
; calculation.
;
; You are free to use this code, or a portion thereof, as long as an appropriate
; acknowledgement is made.
;
; Questions, suggestions and comments to hoodj@topaz.cqu.edu.au.
.model tiny
.286p
.code
MaxPath equ 80 ; These values from dir.h
MaxDir equ 66
len equ MaxPath + (2 * MaxDir) ; Byte length to keep resident
intdos MACRO function, service
IFB <service>
mov ah, function
ELSE
mov ax, (function shl 8) + service
ENDIF
int 21h
ENDM
byt equ <byte ptr>
wrd equ <word ptr>
aamhex equ <db 0d4h, 10h> ; Split AL into AH and AL (12h => 0102h)
aadhex equ <db 0d5h, 10h> ; Merge AH and AL into AL (0102h => 12h)
org 16h ; Segment address of parent
parent dw ?
org 2ch ; Segment address of environment
env dw ?
org 81h ; Where the commandline starts
cmdline db ?
org 100h ; Finally, the start of the program
start: mov prgseg, ds ; Store the program's data segment
cld ; String op's left-to-right
mov ax, parent ; Obtain the parent PSP
mov ds, ax
mov ax, env ; Parent environment
mov es, ax
mov ds, ax
xor di, di ; First environment variable
xor al, al ; Null terminator
mov cx, 0ffffh ; Ensure the entire env. is scanned
find: cmp byt [di], 'M' ; Find 'MTMEM='
je rest ; Got the 'M', check the rest
scan: repne scasb ; Find the next env. variable
cmp byt [di], 0 ; There are no more
jne find
mov ds, cs:prgseg
lea dx, enverr ; Tell the user to set
intdos 9 ; the environment variable
ret ; and exit
rest: IRPC M, TMEM=
inc di
cmp byt [di], '&M&'
jne scan
ENDM
inc di
mov cs:pathst, di ; In case I have to search for path
cmp byt [di], '#' ; Is it already installed?
jne installed
mov es, cs:prgseg ; Restore ES to the program segment
mov bx, 1000h ; Make the program the 64k it should be
intdos 4ah
intdos 58h, 2 ; Get current UMB state
push ax ; and save it
intdos 58h, 0 ; Get current allocation strategy
push ax ; and save it
mov bx, 1 ; Link in UMB
intdos 58h, 3
mov bx, 81h ; Best fit high then low
intdos 58h, 1
mov bx, (len + 15) shr 4 ; Number of paragraphs to keep
intdos 48h ; Allocate the memory
dec ax
mov es,ax ; The MCB of the newly allocated memory
inc ax
mov word ptr es:[1],ax ; Make the memory block own itself
mov dx, ds ; Save the environment pointer
mov bx, di
mov cx, cs
dec cx
mov ds, cx ; MCB of the program
mov si, 8
mov di, si
movsw ; Copy the DOS 4.0+ program name into
movsw ; the new memory block's MCB
movsw
movsw
mov ds, dx ; Retrieve the environment pointer
mov di, bx
mov dx, ax
call write ; Modify the environment variable
pop bx ; Restore allocation strategy
intdos 58h, 1
pop bx ; Restore UMB state
intdos 58h, 3
jmp finish
installed: ; The memory has already been allocated
or cs:flags, 110b ; Don't create the previous directories
call read ; Get the segment into DX
finish: mov es, dx ; Segment to place parameters
mov ds, cs:prgseg
lea si, cmdline
cmp byt [si], 0dh ; No parameters
je done
param: lodsb
cmp al, ' ' ; Ignore spaces
je param
cmp al, 9 ; and replace tabs
jne tstarg
mov byt [si-1], ' ' ; with a space
jmp param
tstarg: cmp al, ';' ; Is it a previous directory?
je prev
mov di, 0 ; Offset for directory structure path
or flags, 001b ; Indicate a path was specified
jmp copy
prev: lodsb
cmp al, ';' ; Before previous directory
je bprev
mov di, MaxPath ; Offset for prev[0]
or flags, 010b
jmp copy
bprev: lodsb
mov di, MaxPath+MaxDir ; Offset for prev[1]
or flags, 100b
copy: cmp al, ' ' ; End of this parameter
je null
cmp al, 0dh
je null
stosb
lodsb
jmp copy
null: mov byt es:[di], 0 ; Place the terminating null
cmp di, MaxPath ; If copying the path
jae testsp ; point BX to its end
mov bx, di
testsp: cmp al, ' ' ; More parameters?
je param
done: test flags, 001b ; Was a path entered?
jnz append ; Yes, so don't search for one
mov bx, es ; BX has the memory segment
mov ax, env ; Get the environment segment
mov dx, ax ; DX has the environment segment
mov es, ax
mov di, pathst ; At the #### of MTMEM=####
add di, 4 ; Point to its terminating null
xor al, al
mov cx, 0ffffh
envend: repne scasb ; End of environment variable
cmp byt es:[di], 0 ; End of environment?
jne envend
inc di ; Point past the word stored after
inc di ; the environment variables to get
i